import type {
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  DoctorPage,
  FollowType,
  Image,
  KnowledgePage,
  KnowledgeParams,
  PageParams,
  PartialConsult,
  TopDep
} from '@/types/consult'
import { request } from '@/utils/request'

// 获取首页文章列表
export const getKnowledgeList = (pramas: KnowledgeParams) =>
  request<KnowledgePage>('/patient/home/knowledge', 'GET', pramas)

// 获取关注医生列表
export const getDoctorList = (pramas: PageParams) =>
  request<DoctorPage>('/home/page/doc', 'GET', pramas)

// 关注和取消关注
export const followDoctor = (id: string, type: FollowType) => request('/like', 'POST', { id, type })

// 获取科室列表数据
export const getAllDep = () => request<TopDep[]>('/dep/all', 'GET')

// 上传图片
export const uploadImg = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('/upload', 'POST', fd)
}

// 获取预支付信息
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('/patient/consult/order/pre', 'GET', params)

// 生成订单接口
export const createConsultOrder = (params: PartialConsult) =>
  request<{ id: string }>('/patient/consult/order', 'POST', params)

// 支付接口
export const getConsultOrderPayUrl = (params: {
  paymentMethod: number
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('/patient/consult/pay', 'POST', params)

// 获取问诊订单详情
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('/patient/consult/order/detail', 'GET', { orderId })

// 根据处方id获取处方单
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`/patient/consult/prescription/${id}`, 'GET')

// 问诊评价
export const evaluateConsultOrder = (pramas: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request('/patient/order/evaluate', 'POST', pramas)

// 获取问诊记录列表数据
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

// 取消订单
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')

// 删除订单
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')
